<!-- 企业信息查询 -->
<template>
  <div class="home-page-content">
    <h3 class="mb-20">大数据采集</h3>
    <Form ref="formData" :model="formData" :label-width="80">
      <Row :gutter="30">
        <Col span="6">
          <FormItem label="项目名称" prop="projectName">
            <Input v-model="formData.projectName" placeholder="请输入"></Input>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="地区" prop="city">
            <CityCascader ref="cityCascader" @getProvince="getProvince" />
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="产业标记" prop="industryAssigns">
            <Select v-model="formData.industryAssigns" placeholder="全部" multiple>
              <Option :value="it.name" v-for="(it, index) in industryAssignsList" :key="index">{{ it.name }}</Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row :gutter="30">
        <Col span="6">
          <FormItem label="审核状态" prop="auditStatus">
            <Select v-model="formData.auditStatus" placeholder="全部" clearable>
              <Option :value="value" v-for="(label, value) in EnumAuditStatus" :key="value">{{ label }}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="发布状态" prop="publishStatus">
            <Select v-model="formData.publishStatus" placeholder="全部" clearable>
              <Option :value="value" v-for="(label, value) in EnumPublishStatus" :key="value">{{ label }}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="组织范围" prop="parentOrgId">
            <OrganizationalTree v-model="formData.parentOrgId" />
          </FormItem>
        </Col>

        <Col span="6" class="com-action-search-btn">
          <Button type="primary" icon="md-search" @click="handleSubmit('formData')">查询</Button>
          <BtnPlain type="primary" @click="handleReset('formData')">
            <Icon type="md-refresh" />
            <span>重置</span>
          </BtnPlain>
        </Col>
      </Row>
    </Form>
    <div class="com-action-table-btn">
      <Button type="primary" @click="goToAdd">
        <Icon type="md-add" />
        <span>新建经营信息</span>
      </Button>
    </div>
    <Table :columns="columns" :data="listData">
      <template slot-scope="{ row }" slot="location">
        <BtnText type="primary" @BtnClick="onViewLocation(row)">查看定位</BtnText>
      </template>
      <template slot-scope="{ row }" slot="publishStatus">
        <BtnPlain
          :type="row.publishStatus === 'Released' ? 'primary' : row.publishStatus === 'Unreleased' ? 'green' : 'error'"
        >{{ row.publishStatusName }}</BtnPlain>
      </template>
      <template slot-scope="{ row }" slot="action">
        <BtnText v-if="row.publishStatus === 'Obsolete'" type="warning" @BtnClick="onPublish(row)">重新发布</BtnText>
        <BtnText v-if="row.publishStatus === 'Unreleased'" type="warning" @BtnClick="onPublish(row)">发布</BtnText>
        <BtnText v-if="row.publishStatus === 'Unreleased'" type="error" @BtnClick="onCancel(row)">作废</BtnText>
        <BtnText v-if="row.publishStatus !== 'Released'" type="green" @BtnClick="goToAdd(row,'edit')">编辑</BtnText>
        <BtnText type="primary" @BtnClick="onView(row)">详情</BtnText>
      </template>
    </Table>
    <PageAtion
      v-if="formData.total"
      :total="formData.total"
      :size.sync="formData.size"
      :page.sync="formData.page"
      @pageSizeChange="pageSizeChange"
    />
    <ViewLocation v-model="modalValueLocation" :info="locationInfo" />
  </div>
</template>

<script>
import ViewLocation from '@/pages/businessInformationManage/common/viewLocation.vue'
import CityCascader from '@/pages/components/cityCascader'
import OrganizationalTree from '@/pages/components/organizationalTree'
import { bigdataGetPage, bigdataPublishData, bigdataObsoleteData } from '@/api/dataCapture.js'
import { getDictTreeByParentId } from '@/api/system.js'

export default {
  name: 'dataCapture',
  components: { ViewLocation, CityCascader, OrganizationalTree },
  data () {
    return {
      formData: {
        projectName: '',
        publishStatus: '',
        auditStatus: '',
        industryAssigns: [],
        parentOrgId: '',
        province: '',
        city: '',
        page: 1,
        size: 10,
        total: 10,
      },
      columns: [
        {
          title: '项目名称',
          key: 'projectName',
          minWidth: 160,
          tooltip: true
        },
        {
          title: '信息类型',
          key: 'infoTypeName',
          minWidth: 160,
        },
        {
          title: '省份',
          key: 'province',
          minWidth: 120,
        },
        {
          title: '城市',
          key: 'city',
          minWidth: 120,
        },
        {
          title: '产业标记',
          key: 'industryAssign',
          minWidth: 160,
          tooltip: true
        },
        {
          title: '项目地址',
          slot: 'location',
          minWidth: 120,
        },
        {
          title: '预计产值规模(万元)',
          key: 'outputScale',
          minWidth: 160,
        },
        {
          title: '业主方',
          key: 'ownerCompanyName',
          minWidth: 160,
          tooltip: true
        },
        {
          title: '施工方',
          key: 'constructionName',
          minWidth: 160,
          tooltip: true
        },
        {
          title: '发布状态',
          slot: 'publishStatus',
          width: 160,
        },
        {
          title: '操作',
          slot: 'action',
          width: 210,
          align: 'center',
          fixed: 'right'
        },
      ],
      listData: [],
      selectData: [{ value: 1, label: 'New York' }],
      modalValueLocation: false,
      locationInfo: {},
      // 审核状态
      EnumAuditStatus: {
        PendingReview: '待提交',
        UnderReview: '审核中',
        Pass: '通过',
        NotPass: '驳回',
        CancelAudit: '已撤回',
      },
      // 发布状态
      EnumPublishStatus: {
        Unreleased: '未发布',
        Released: '已发布',
        Obsolete: '已作废',
      },
      industryAssignsList: []
    };
  },
  async created () {
    this.init()
    this.industryAssignsList = await getDictTreeByParentId({ parentId: 'COMPANY_SERVICE' })
  },
  methods: {
    async init () {
      const request = { ...this.formData }
      const { data, page, size, total } = await bigdataGetPage(request)
      this.listData = data
      this.formData = { ...this.formData, ...{ page, size, total } }
    },
    getProvince(arr){
      this.formData.province = arr[0] || ''
      this.formData.city = arr[1] || ''
    },
    handleReset (name) {
      this.$refs['cityCascader'].reset();
      this.$refs[name].resetFields();
      this.init()
    },
    handleSubmit (name) {
      this.init()
    },
    pageSizeChange (row) {
      this.init()
    },
    onViewLocation (row) {
      this.modalValueLocation = true
      this.locationInfo = row
    },
    // 新建经营信息
    goToAdd (row = {}, type = 'add') {
      this.$router.push({ path: '/dataCaptureAdd', query: { type, busiInfoId: row.busiInfoId } })
    },
    onView (row) {
      const path = row.publishStatus === 'Released' ? 'businessInformationDetails' : '/dataCaptureDetails'
      this.$router.push({ path, query: { busiInfoId: row.busiInfoId } })
    },
    // 发布 or 重新发布
    onPublish (row) {
      this.$Modal.confirm({
        title: "温馨提示",
        content: '将发布此项目，请确认是否继续？',
        onOk: async () => {
          await bigdataPublishData({ busiInfoId: row.busiInfoId })
          this.$Message.success('操作成功！');
          this.init()
        },
      })
    },
    // 作废
    onCancel (row) {
      this.$Modal.confirm({
        title: "温馨提示",
        content: '将作废此项目，请确认是否继续？',
        onOk: async () => {
          await bigdataObsoleteData({ busiInfoId: row.busiInfoId })
          this.$Message.success('操作成功！');
          this.init()
        },
      })
    }
  },
};
</script>

<style lang="less" scoped>
.mb-20 {
  margin-bottom: 20px;
}
</style>
